import axios from 'axios'
import nProgress from 'nprogress'

const request = axios.create({
  baseURL: '/sphapi',
  timeout: 10000,
  headers: {
    token: localStorage.getItem('token'),
    // userTempId: "ca1bdcc1-d4a3-4e9f-951e-2ccbe8e610e8"
  }
})
request.interceptors.request.use((config) => {

  // 开启进度条
  nProgress.start()
  return config
})

request.interceptors.response.use((res) => {

  // 关闭进度条
  nProgress.done()

  return res.data.data
}, (err) => {
  // 关闭进度条
  nProgress.done()
  return Promise.reject(err)
})

export default request